﻿@model string
@{
    Layout = null;
}
<link href="@Url.Content("~/Content/ztree/zTreeStyle.css")?ver=3.5.01" rel="stylesheet" />
<script src="@Url.Content("~/Scripts/ztree/jquery.ztree.all-3.5.min.js")?ver=3.5.01" type="text/javascript"></script>
<ul id="hostTree" class="ztree">
    
</ul>
<script type="text/javascript">
    $(function () {
        var treeSetting = {
            check: { enable: true },
            view: { showIcon: false }
        };
        var treeNodes = @Html.Raw(Model ?? string.Empty);
        $.extend(treeSetting, @Html.Raw(ViewBag.TreeSetting == null ? "{}" : ViewBag.TreeSetting as string));
        $.fn.zTree.init($('#hostTree'), treeSetting, treeNodes);
    });

    function getCheckHostIds() {
        var ztreeObj = $.fn.zTree.getZTreeObj('hostTree'),
                checkedNodes = ztreeObj.getNodesByFilter(filterZTree);
        var selectHostIds = $.map(checkedNodes, function(ztreeNode) {
            return ztreeNode.expandos.hostId;
        });
        return selectHostIds;
    }
    
    function filterZTree(ztreeNode) {
        return ztreeNode.expandos && ztreeNode.expandos.hostId && ztreeNode.checked;
    }
</script>